@extends('layouts.admin')

@section('scripts')
    <script src="{{asset('DatePicker/WdatePicker.js')}}" type="text/javascript"></script>
@stop

@section('content')
    <ol class="breadcrumb">
        <li class="breadcrumb-item">后台管理</li>
        <li class="breadcrumb-item">交易管理</li>
        <li class="breadcrumb-item active">线下支付申请</li>
    </ol>

    <div class="content-div">
        <form method="post" id="listForm">
            {{form_verify_field()}}
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="listtable">
                <thead>
                <tr>
                    <th width="20">选</th>
                    <th width="300">提交人</th>
                    <th>支付流水</th>
                    <th width="200">申请时间</th>
                    <th width="180">选项</th>
                </tr>
                </thead>
                <tbody>
                @foreach($items as $item)
                <tr>
                    <td><input title="" type="checkbox" class="checkmark" name="delete[]" value="{{$item['id']}}" /></td>
                    <td><a>{{$item['user']['username']}}</a></td>
                    <td>{{$item['pay_no']}}</td>
                    <td>{{@date('Y-m-d H:i:s', $item['created_at'])}}</td>
                    <td>
                        <div class="btn-group-sm">
                            <a><span class="btn btn-primary" onclick="acceptHandler({{$item['id']}}, 1)">同意</span></a>
                            <a><span class="btn btn-danger" onclick="acceptHandler({{$item['id']}}, 2)">拒绝</span></a>
                            <a href="{{admin_url('order/detail?order_id='.$item->order_id)}}" target="_blank"><span class="btn btn-default">查看订单</span></a>
                        </div>
                    </td>
                </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="11">
                        <div class="float-right">{!! $pagination !!}</div>
                        <div class="btn-group-sm">
                            <label class="form-check-label"><input type="checkbox" class="checkmark" data-action="checkall"> {{trans('common.selectall')}}</label>
                            <button type="button" class="btn btn-default btn-action" disabled="disabled" id="batchdelete">批量删除</button>
                            <button type="button" class="btn btn-default" data-action="refresh">刷新</button>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
@stop

@section('foot')
    <script type="text/javascript">
        $(function () {
            $(document).on('click', function () {
                if ($(".checkmark:checked").length > 0){
                    $(".btn-action").enable();
                } else {
                    $(".btn-action").disable();
                }
            });

            $("#batchdelete").on('click', function () {
                DSXUI.showConfirm('确认要删除所选信息吗?', function () {
                    $("#listForm").ajaxSubmit({
                        url:'{{admin_url('payunderline/delete')}}',
                        beforeSend:DSXUI.showSpinner,
                        success:function () {
                            setTimeout(function () {
                                DSXUI.hideSpinner();
                                DSXUtil.reFresh();
                            }, 500);
                        }
                    });
                });
            });
        });
        function acceptHandler(id, status) {
            $.ajax({
                type:'POST',
                url:'payunderline/accept',
                data:{id:id,status:status},
                success:function () {
                    DSXUtil.reFresh();
                }
            });
        }
    </script>
@stop
